﻿using FinancialManagement.Application.Command.SalesReturnCommand;
using FinancialManagement.Infrstructre.Interface;
using MediatR;

namespace FinancialManagement.Application.CommandHandler.SalesReturnCommandHandler
{
    public class StateUpdSalesReturnCommandHandler : IRequestHandler<StateUpdSalesReturnCommand, int>
    {

        ISalesReturnRepository srRep;

        public StateUpdSalesReturnCommandHandler(ISalesReturnRepository srRep)
        {
            this.srRep = srRep;
        }

        public async Task<int> Handle(StateUpdSalesReturnCommand request, CancellationToken cancellationToken)
        {
            var res = (await srRep.GetAllAsyns()).Where(c => c.SalesReturnId == request.SalesReturnId).First();
            if (res != null)
            {
                res.SalesReturnState = 2;
                await srRep.UpdateAsync(res);
            }
            return 1;
        }
    }
}
